import { defineStore } from 'pinia';

export const useMain = defineStore('main', {
    // 相当于vue2的data
    state: () => {
        return {
            title: 'vue3Demo',
            userName: '',
            count: 0
        }
    },
    // 相当于计算属性
    getters: {
        // count累加
        countAdd: (state) => {
            return state.count++;
        }
    },
    actions: {
        // 相当于vuex的mutation + action,可以写同步和异步，这里示例赋值用户名
        setUserName(userName: string) {
            this.userName = userName;
        }
    }
});
